package fun.chutianshu;

public class Main {

    public static void main(String[] args) {
	// write your code here
        String[] fields = { "name", "position", "salary" };
        String table = "employee";
        String insert = buildInsertSql(table, fields);
        System.out.println(insert);
        String s = "INSERT INTO employee (name, position, salary) VALUES (?, ?, ?)";
        System.out.println(s.equals(insert) ? "测试成功" : "测试失败");
    }

    static String buildInsertSql(String table, String[] fields) {
        // TODO:
        String sql = "INSERT INTO " + table + " (";
        for(String s:fields){
            sql += s;
            sql += ", ";
        }
        System.out.println(sql);
        //用取子串的方法，删除掉末尾两个多余字符
        sql = sql.substring(0, sql.length() - 2);
        System.out.println(sql);
        sql += ") VALUES (?, ?, ?)";
        System.out.println(sql);
        return sql;
    }
}
